import sys
sys.path.append('..')

import unittest

from pinyincommon import splitpinyin
from pinyincommon import ShengmuPinyinException,DiaoPinyinException,YunmuPinyinException

class testsplitpinyin(unittest.TestCase):
    """
    test the check test split
    """
    def testshengmu(self):
        """
        """
        dic = {'zheng5':'zh','yu4':'','wu1':''}
        for k in dic.keys():
            self.assertEqual(splitpinyin(k)['shengmu'],dic[k])

    def testyunmu(self):
        """
        """
        dic = {'zheng5':'eng',
                'weng1':'ueng','wu1':'u',
                'yi2':'i','ya1':'ia',
                'yu3':'v','yue2':'ve',
                'ju4':'v','qu2':'v','xu3':'v',
                'que2':'ve','jue2':'ve',
                'qiu1':'iou','qun4':'uen','kui1':'uei',
                'yo2':'o'}
        for k in dic.keys():
            self.assertEqual(splitpinyin(k)['yunmu'],dic[k])

    def testdiao(self):
        dic = splitpinyin("zheng5")
        self.assertEqual(dic['diao'],5)

    def exshengmu(self):
        self.assertRaise(ShengmuPinyinException,splitpinyin,"zhea5")

    def exyunmu(self):
        self.assertRaises(YumuPinyinException,splitpinyin,"qwe5")

    def exdiao(self):
        self.assertRaises(DiaoPinyinException,splitpinyin,"zheng")


if __name__=="__main__":
    unittest.main()
